﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Aulac.Srv.Db.Provider; using Aulac.Srv.Db.Connect;
using Aulac.Rsc.Ems; using Aulac.Rsc.Ems.Tags;
using Aulac.Global.Enums; using Aulac.Global.Data; using Aulac.Global.Common; using Aulac.Global.Xml;
using Aulac.Srv.Db.Common;
using System.Data;
using System.Data.Common;

namespace Aulac.Srv.Db.Data.Ems.MdcFiles
{
    /*** Other Write: Thangnc ***/
    /*** Code Date: 09172010 ***/

    partial class MdcFilePntMng
    {

        /// <summary>
        /// Set thong tin Benh an cua BN
        /// </summary>
        /// <param name="ePntInfo">Chua thong tin Benh an</param>
        /// <param name="pCmdType">Kieu truy van</param>
        /// <returns></returns>
        private string ExecQueryMdcFilePntDb(XmlElement ePntInfo, QueryCmdTypes pCmdType)
        {
            /*** Other Write: Thangnc ***/
            /*** Code Date: 09172010 ***/

            string sMdcFilePrkID = "";
            Aulac.Srv.Data.XmlQuery.SrvExecXmlQueryData query = new Aulac.Srv.Data.XmlQuery.SrvExecXmlQueryData(DbDataProvider);

            XmlElement eHeader = query.SetVchHeaderElm(pCmdType);

            query.SetTableName(eHeader, TableNames.MdcFile_PntExam);
            query.ObjQueryVchHeader.AddFieldPrk(tagMdcFiles.MdcFiles.MdcFilePrkID, System.Data.DbType.Decimal, KeyTypes.AutoNumber, RefValueTypes.InnerHeaderElm);
            query.ObjQueryVchHeader.AddFieldResultItem(tagMdcFiles.MdcFiles.MdcFilePrkID, System.Data.DbType.Decimal, RefValueTypes.InnerAndResultHeaderElm);
            query.ImportData(query.ObjQueryVchHeader, ref eHeader, ePntInfo);
            sMdcFilePrkID = XmlProcess.GetValueVchHeader(query.XmlQueryDoc, tagMdcFiles.MdcFiles.MdcFilePrkID);
            query.ObjQueryVchHeader.AddValueParamFilterItem(tagMdcFiles.MdcFiles.MdcFilePrkID, tagMdcFiles.MdcFiles.MdcFilePrkID, sMdcFilePrkID);

            XmlDataDocument xmlDoc = query.ExecureQuery();

            sMdcFilePrkID = XmlProcess.GetValueVchHeader(xmlDoc, tagMdcFiles.MdcFiles.MdcFilePrkID);
            XmlProcess.SetAtrb(ref ePntInfo, tagMdcFiles.MdcFiles.MdcFilePrkID, sMdcFilePrkID);

            return sMdcFilePrkID;

        }

        private bool DelMdcFilePntDb(string pPntPrkID, string pHspInNum)
        {
            sqlQuery = SqlHelper.CreateSqlDelete(TableNames.MdcFile_PntExam, tagMdcFiles.Pnt.PntPrkID, tagMdcFiles.Pnt.HspInNum);
            return DbDataProvider.ExecuteNonQuery(ref mDbCmd, sqlQuery, pPntPrkID, pHspInNum) >= 0;
        }

        /// <summary>
        /// Kiem tra xem PntPrkID da co trong MdcFile_PntExam chua
        /// </summary>
        /// <param name="pPntPrkID"></param>
        /// <returns>Neu khong co Return False, Nguoc lai Return True</returns>
        private bool IsExistPntInMdcFile(string pPntPrkID)
        {
            object obj = DbDataProvider.SelectValueFromDb(TableNames.MdcFile_PntExam, tagMdcFiles.Pnt.PntPrkID, tagMdcFiles.Pnt.PntPrkID, pPntPrkID);
            return !ValueHelper.isEmpty(obj);
        }
    }
}
